﻿using ERPU8WebApi.Until;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ERPU8WebApi.Models
{
    /// <summary>
    /// 产成品入库单
    /// </summary>
    public class FinishedProductsWarehousingBill : BaseOrderModel
    {
        public FinishedProductsWarehousingBillHeadClass head;
        public List<FinishedProductsWarehousingBillBodyClass> body;
        //public string xmlHead;
        //public string xmlBody;
    }
    public class FinishedProductsWarehousingBillHeadClass : BaseOrderModelClass
    {
        public string id;                       //主关键字段
        public string brdflag;                  //收发标志
        public string cvouchtype;               //单据类型
        public string csysbarcode;              //单据条码
        public string cwhcode;                  //仓库编码
        public string ddate;                    //入库日期
        public string ccode;                    //入库单号
        public string cmemo;                    //备注
        public string crdcode;                  //入库类别编码
        public string cdepcode;                 //部门编码
        public string cprobatch;                //生产批号
        public string cmaker;                   //制单人
        public string cwhname;                  //仓库
        public string cdepname;                 //部门
        public string crdname;                  //入库类别
        public string csource;                  //单据来源
        public string cbustype;                 //业务类型
        public string vt_id;                    //模版号
        public string bisstqc;                  //库存期初标记
        public string cmpocode;                 //生产订单号
        public string bpufirst;                 //采购期初标志
        public string biafirst;                 //存货期初标志 
        public string iproorderid;              //生产订单ID
        public string ireturncount;             //打回次数
        public string iverifystate;             //工作流审批状态
        public string iswfcontrolled;           //是否工作流控制
        public string ufts;                     //时间戳
        public string cmodifyperson;            //修改人
        public string dnmaketime;               //制单时间
        public string bomfirst;                 //委外期初 
        public string chinvsn;                  //序列号
        public string iPrintCount;              //打印次数
        public string cchecksignflag;           //
        public string editprop;                 //编辑属性：A表新增，M表修改，D表删除，
       
       
    }
    public class FinishedProductsWarehousingBillBodyClass : BaseOrderModelClass
    {
        public string cassunit;                    //辅计量单位编码


        public string autoid;                      //主关键字段
        public string id;                          //与主表关联项
        public string cinvcode;                    //产品编码
        public string cinvaddcode;                 //产品代码
        public string cinvname;                    //产品名称
        public string cinvstd;                     //规格型号
        public string cinvccode;                   //存货大类编码
        public string cinvm_unit;                  //主计量单位
        public string cinvdefine1;                 //存货档案自定义项1  操作手册
        public string cinvdefine2;                 //对应软件
        public string cinvdefine3;                 //物料种类
        public string cinvdefine4;                 //配套集中器、采集器、手持机、写卡机、卡片
        public string cinvdefine5;                 //推荐等级
        public string cinvdefine6;                 //说明书
        public string cinvdefine7;                 //关键字分类
        public string cinvdefine10;                //存货描述
        public string cinvdefine13;                //参考价
        public string cbatch;                      //批号
        public string inquantity;                  //应收数量
        public string iquantity;                   //数量
        public string iunitcost;                   //单价
        public string iprice;                      //金额
        public string cdefine24;                   //
        public string cdefine25;                   //
        public string cdefine27;                   //
        public string impoids;                     //生产订单子表ID
        public string brelated;                    //是否联副产品
        public string cmocode;                     //生产订单号
        public string imoseq;                      //生产订单行号
        public string cmolotcode;                  //生产批号
        public string corufts;                     //对应单据时间戳
        public string isotype;                     //需求跟踪方式
        public string cdemandmemo;                 //需求分类代号说明
        public string iordertype;                  //销售订单类别
        public string iorderdid;                   //销售订单id 
        public string bcosting;                    //核算成本标志
        public string bvmiused;                    //代管消耗标识
        public string iexpiratdatecalcu;           //有效期推算方式
        public string cbatchproperty6;             //批次属性6
        public string cbinvsn;                     //序列号
        public string irowno;                      //行号
        public string cbsysbarcode;                //单据行条码
        public string taskguid;                    //
        public string editprop;                    //编辑属性：A表新增，M表修改，D表删除

    }
    public class FinishedProductsWarehousingController : BaseOrderModelController
    {
        //查询时返回对象
        public override BaseOrderModel GetBaseOrderModel(string xmlHead, List<string> xmlBodyList, int bodyCount)
        {
            FinishedProductsWarehousingBill soo = new FinishedProductsWarehousingBill();
            FinishedProductsWarehousingBillHeadClass head = new FinishedProductsWarehousingBillHeadClass();
            List<FinishedProductsWarehousingBillBodyClass> body = new List<FinishedProductsWarehousingBillBodyClass>();

            xmlHead = xmlHead.Replace("=", "");
            string[] strArray = xmlHead.Split(new string[] { "\"" }, StringSplitOptions.None);
            for (int i = 0; i < strArray.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (SerializeLibrary.ContainProperty(head, strArray[i]))
                    {
                        if (i + 1 < strArray.Length)
                        {
                            if (head.GetType().GetField(strArray[i]) != null)
                            {
                                head.GetType().GetField(strArray[i]).SetValue(head, strArray[i + 1]);
                            }
                        }
                    }
                }
            }
            for (int n = 0; n < bodyCount; n++)
            {
                FinishedProductsWarehousingBillBodyClass soob = new FinishedProductsWarehousingBillBodyClass();
                xmlBodyList[n] = xmlBodyList[n].Replace("=", "");
                string[] strArrayB = xmlBodyList[n].Split(new string[] { "\"" }, StringSplitOptions.None);
                for (int i = 0; i < strArrayB.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        if (SerializeLibrary.ContainProperty(soob, strArrayB[i]))
                        {
                            if (i + 1 < strArrayB.Length)
                            {
                                if (soob.GetType().GetField(strArrayB[i]) != null)
                                {
                                    soob.GetType().GetField(strArrayB[i]).SetValue(soob, strArrayB[i + 1]);
                                }
                            }
                        }
                    }
                }

                body.Add(soob);
            }
            soo.head = head;
            soo.body = body;
            return soo;
        }

        #region 转移到父类里，这里不需要
        ////新增或修改时 将对象转化为xml
        //public string ReturnXmlHead(FinishedProductsWarehousingBillHeadClass soo)
        //{
        //    string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\XML\产成品入库单\表头模板.txt";
        //    string xmlHead = System.IO.File.ReadAllText(path);
        //    int indexHead = xmlHead.IndexOf("<rs:data>");
        //    string head = xmlHead.Substring(0, indexHead + 9);
        //    string center = "<z:row ";
        //    Dictionary<string, string> dic1 = SerializeLibrary.GetFiledNameValue(soo);
        //    foreach (var item in dic1)
        //    {
        //        center += item.Key + "=" + item.Value + " ";
        //    }
        //    center += "/> ";
        //    int indexBody = xmlHead.IndexOf("</rs:data>");
        //    string ends = xmlHead.Substring(indexBody, xmlHead.Length - indexBody);
        //    string xml = head + center + ends;
        //    return xml;
        //}

        //public string ReturnXmlBody(List<FinishedProductsWarehousingBillBodyClass> soo)
        //{
        //    string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\XML\产成品入库单\表体模板.txt";
        //    string xmlHead = System.IO.File.ReadAllText(path);
        //    int indexHead = xmlHead.IndexOf("<rs:data>");
        //    string head = xmlHead.Substring(0, indexHead + 9);
        //    string centers = "";
        //    for (int i = 0; i < soo.Count; i++)
        //    {
        //        string center = "<z:row ";
        //        Dictionary<string, string> dic1 = SerializeLibrary.GetFiledNameValue(soo[i]);
        //        foreach (var item in dic1)
        //        {
        //            center += item.Key + "=" + item.Value + " ";
        //        }
        //        center += "/> ";
        //        centers += center;
        //    }
        //    int indexBody = xmlHead.IndexOf("</rs:data>");
        //    string ends = xmlHead.Substring(indexBody, xmlHead.Length - indexBody);
        //    string xml = head + centers + ends;
        //    return xml;
        //}

        #endregion
    }

}